package com.redpack.redpost.struts.action.admin;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.redpack.redpost.struts.form.admin.agregarSubseccionForm;
import com.redpack.redpost.util.dao.adminDAO;
import com.redpack.redpost.util.to.generalUtil;

public class agregasubseccionval extends Action {
	
	public ActionForward execute(
			ActionMapping mapping, 
			ActionForm form, 
			HttpServletRequest request, 
			HttpServletResponse response) throws Exception {
		
		/*boolean logginVal = generalUtil.isLoggedIn(request);
		if(logginVal!=true)
			return mapping.findForward("noLogin") ;*/
		
		agregarSubseccionForm f = (agregarSubseccionForm)form;
		boolean val = false;
		if(f != null){
			if( f.getCve_subseccion() > 0 ){
				val = adminDAO.updSubseccion(f.getCve_subseccion(),f.getNombre(),f.getIdioma(),f.getSeccion(),f.getOrden());
				return mapping.findForward("successEdit") ;
			}else{
				val = adminDAO.saveSubseccion(f.getNombre(),f.getIdioma(),f.getSeccion(),f.getOrden());
			}
		}
		String[][] idiomas = generalUtil.obtieneIdiomas();
		String[][] secciones = generalUtil.obtieneSecciones();
		
		request.setAttribute("idiomas", idiomas);
		request.setAttribute("secciones", secciones);
		request.setAttribute("orden_sel", "0");
		
		if( val == true ){
			request.setAttribute("correcto", ""+val);
		}else{
			request.setAttribute("correcto", "");
		}
		
		return mapping.findForward("success") ;
	}

}
